package com.lotter.common.util;


import java.io.File;
import java.io.IOException;

import org.springframework.util.FileCopyUtils;
import org.springframework.web.multipart.MultipartFile;

import com.lotter.common.context.YcContext;

/**
 * 上传图片
 * @author zhangzechi
 *
 */
public class UploadUtils {
	
	/**
	 * 上传文件方法
	 * @param request
	 * @return
	 */
	public static String UploadFile(MultipartFile multipartFile,String path) throws IOException{
		StringBuilder uploadDir = new StringBuilder();
		uploadDir.append(path);
		File dirPath = new File(uploadDir.toString());
		if(!dirPath.exists()){
			dirPath.mkdirs();
	    }
		String fileName = multipartFile.getOriginalFilename();
		String SuffixName =  fileName.substring(fileName.lastIndexOf("."));
		long sysdane=System.currentTimeMillis();
		FileCopyUtils.copy(multipartFile.getBytes(), new File(uploadDir+"/"+sysdane+SuffixName));
		return YcContext.DOMAIN_NAME + YcContext.IMAGE_PATH +  sysdane +SuffixName;
		//http://api.1vs30.com//statics/uploads/image1476367697938.png
		//http://api.1vs30.com/uploads/image/5634636746574.jpg
	}
	
	

	
}
